package top.huhuiyu.springboot.study.controller;

import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;
import top.huhuiyu.springboot.study.base.BaseDataResult;
import top.huhuiyu.springboot.study.base.BaseResult;
import top.huhuiyu.springboot.study.base.PageBean;
import top.huhuiyu.springboot.study.base.PageResult;
import top.huhuiyu.springboot.study.entity.SoftwareType;
import top.huhuiyu.springboot.study.service.SoftwareTypeService;

import java.util.List;

/**
 * @author 胡辉煜
 */
@RestController
@RequestMapping("/softwaretype")
@RequiredArgsConstructor
public class SoftwareTypeController {
  private final SoftwareTypeService softwareTypeService;

  @PostMapping("")
  public BaseResult insert(@RequestBody SoftwareType softwareType) {
    return softwareTypeService.insert(softwareType);
  }

  @GetMapping("/{id}")
  public BaseDataResult<SoftwareType> queryByKey(@PathVariable Integer id) {
    return softwareTypeService.queryByKey(id);
  }

  @PutMapping("")
  public BaseResult update(@RequestBody SoftwareType softwareType) {
    return softwareTypeService.update(softwareType);
  }

  @DeleteMapping("/{id}")
  public BaseResult delete(@PathVariable Integer id) {
    return softwareTypeService.delete(id);
  }

  @GetMapping("/{pn}/{ps}")
  public BaseDataResult<PageResult<List<SoftwareType>>> query(SoftwareType type, @PathVariable("pn") Integer pn, @PathVariable("ps") Integer ps) {
    return softwareTypeService.query(type, PageBean.instance(pn, ps));
  }


}
